<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>待分配警情详情页</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css"/>
    <style type="text/css">
        .addresslayer {
            padding: 10px;
            width: 94%;
            height: 90%;
            margin: 10px auto;
            display: none;
        }

        .operation_title_m {
            font-size: 16px;
        }
    </style>
</head>
<body>
<div class="ok-body" style="background: #F8F8F8">
    <div class="layui-row ">
        <div class="layui-col-md9" style="background-color:#F8F8F8">
            <div class="layui-row">

                <hr class="layui-bg-gray">
                <fieldset class="layui-elem-field">
                    <legend>警情详情
                        <span class="layui-badge layui-bg-blue">待分派</span>
                    </legend>
                    <div class="layui-field-box " style="margin-left: 30px;height: 40px">

                    </div>
                </fieldset>

            </div>
            <div>
                <div style="background: #d2d2d2">
                    <div style="width: 80%;height: 100%;margin: 0 auto;">
                        <div class="layui-collapse" lay-filter="caseData">
                            <div class="layui-colla-item">
                                <h2 class="layui-colla-title" style="font-size: 16px"><span
                                        id="caseDataChange">隐藏</span>警情信息</h2>
                                <div class="layui-colla-content layui-show" style="background-color:#fdfdfd;">
                                    <div style="background-color:#fdfdfd;padding: 95px 30px 100px 30px;">
                                        <iframe scrolling="no" frameborder="0" src="../caseCommonData/caseData.html"
                                                width="100%"
                                                height="700px" id="caseData"
                                                onload="this.height=0;var fdh=(this.Document?this.Document.body.scrollHeight:this.contentDocument.body.offsetHeight);this.height=(fdh>700?fdh:700);"></iframe>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="layui-col-md3" style="background-color:#f8f8f8;">
            <div>
                <hr class="layui-bg-gray">
                <fieldset class="layui-elem-field">
                    <legend>警情分派</legend>

                    <div style="background-color: #f8f8f8;height: auto;margin:10px 20px 0 20px">

                        <form class="layui-form" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="text-align: left;">警情描述</label>
                                <div class="layui-form-item layui-form-text">
                                    <textarea name="caseDescription" id="caseDescription" required placeholder="请填写……"
                                              class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label" style="text-align: left;">处理单位</label>
                                <div class="layui-form-text layui-form-item">
                                    <select name="procDepartment" id="procDepartment" lay-filter="procDepartment"
                                            lay-verify="required">

                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label" style="text-align: left;">督办级别</label>
                                <div class="layui-form-text layui-form-item">
                                    <select name="procLevel">
                                        <option value="一级">一级</option>
                                        <optgroup>
                                            <option value="二级">二级</option>
                                            <option value="三级">三级</option>
                                            <option value="四级">四级</option>
                                        </optgroup>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <button type="button" class="layui-btn" lay-submit lay-filter="add"
                                        id="uploadListAction" style="float: right">提交
                                </button>

                                <button type="button" class="layui-btn layui-btn-danger" lay-submit lay-filter="deleteCase"
                                        id="deleteCase">删除该警情
                                </button>
                            </div>
                        </form>

                    </div>
                </fieldset>

            </div>
        </div>
    </div>
</div>
<br/>

<script src="../../js/jquery-3.3.1.js"></script>
<script src="../../lib/layui/layui.all.js"></script>
<script src="../../js/model.js"></script>
<script src="../../js/application.js"></script>

<script>
    let processDataHeight = 0
    let caseId = GetQueryString("caseId");
    let reportingContent=GetQueryString("reportingContent");
    //获取警情详细页
    getCaseData(caseId)

    function getCaseData(caseId) {
        $("#caseData").on("load", function () {
            var data = {caseId: caseId}
            this.contentWindow.getParentData(data)
        })
    }

    layui.use(['layedit', 'upload', 'element', 'form'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        var layedit = layui.layedit;
        var upload = layui.upload;
        var element = layui.element;

        //获取派出所信息
        $.ajax({
            url: mainUri + "/dep/getDepartment",
            type: 'post',
            data: {'deepth': 3}
        }).done(function (datas) {
            var list = datas['data'];
            var option;
            for (var i = 0; i < list.length; i++) {
                option += "<option value='" + list[i]['departmentId'] + "'>" + list[i]['departmentName'] + "</option>";
                $("#procDepartment").html(option);
            }
            form.render('select');
        }).fail(function () {
            layer.msg("服务器错误");
        });

        var policeInfo = JSON.parse(window.sessionStorage.getItem("police"));

        //内容判断
        form.on("submit(add)", function (data) {
            var description = $("#caseDescription").val();
            if (description.trim() != "") {
                layer.confirm('确定分派?', {icon: 3, title: '提示'}, function (index) {
                    pendingCase(data);
                });
            } else {
                if(reportingContent==""){
                    reportingContent = $(document.getElementById('caseData').contentWindow.document.getElementById('reportingContent')).html();
                }
                layer.confirm('确定分派?', {icon: 3, title: '提示'}, function (index) {
                    data.field.caseDescription=reportingContent;
                    pendingCase(data);
                });
            }
        });

        //警情删除
        form.on("submit(deleteCase)", function (data) {
            layer.confirm('确定删除该警情吗?', {icon: 3, title: '提示'}, function (index) {
               showloading(true);
               $.ajax({
                    url: mainUri + "/case/deleteByCaseId",
                    data: {
                        "caseId": caseId
                    },
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        showloading(false)
                        if (data.code == 0) {
                            layer.msg("操作成功", {
                                icon: 1, time: 1500, end: function () {
                                    window.opener.location.href = window.opener.location.href;
                                    window.close();
                                }
                            })
                        }
                    },
                    error: function () {
                        showloading(false)
                        alert("服务器错误");
                    }
                });
            });
        });

        //警情分派
        function pendingCase(data) {
            showloading(true);
            var distributionCase = data.field;
            var caseProcInfo = new CaseProcInfo("", new Case(caseId), new User(policeInfo.policeId), policeInfo.departmentName, "", new Department(distributionCase.procDepartment), distributionCase.caseDescription, distributionCase.procLevel, 0);
            //警情分派
            $.ajax({
                url: mainUri + "/caseProcInfo/insert",
                data: {
                    "caseProcInfoJson": JSON.stringify(caseProcInfo)
                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    showloading(false)
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1, time: 1500, end: function () {
                                window.opener.location.href = window.opener.location.href;
                                window.close();
                            }
                        })
                    }
                },
                error: function () {
                    showloading(false)
                    alert("服务器错误");
                }
            });
        }

        //警情详细页的显示隐藏
        element.on('collapse(caseData)', function (data) {
            if (processDataHeight == 0) {
                processDataHeight = $("#processData").height();
            }
            if (!data.show) {
                if (processDataHeight < 800) {
                    $("#processData").height(800)
                }
                $("#caseDataChange").html("显示")
            } else {
                $("#processData").height(processDataHeight)
                $("#caseDataChange").html("隐藏")
            }
        });

    });

    function caseReturnData(returnData) {

    }

    function processReturnData(returnData) {
        $("#processData").height(returnData.height)
        processDataHeight = returnData.height
    }

    function showProcessContent(clickId) {

    }
</script>
</body>
</html>
